package com.jypark.sunbongmahjong.game;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.content.Context;
import android.opengl.GLSurfaceView.Renderer;

import com.jypark.sunbongmahjong.R;
import com.jypark.sunbongmahjong.def.Def;
import com.jypark.sunbongmahjong.info.ImageInfo;

public class GameRenderer implements Renderer {

	private Context context;
	private GL10 mGL;
	private GameMain gameMain;
	private ImageInfo[] m_imgInfo = new ImageInfo[Def.MAX_TEX_SIZE];

	public GameRenderer(Context context) {
		this.context = context;
	}

	@Override
	public void onSurfaceCreated(GL10 gl, EGLConfig config) {
		mGL = gl;
		gameMain = new GameMain(gl);
		gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
		mGL.glEnableClientState(GL10.GL_VERTEX_ARRAY);
		mGL.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
	}

	@Override
	public void onSurfaceChanged(GL10 gl, int width, int height) {

	}

	@Override
	public void onDrawFrame(GL10 arg0) {

		long thisTime = System.currentTimeMillis();

		mGL.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

		gameMain.display(thisTime);
		mGL.glFlush();
		gameMain.afterDraw();
	}

	public void makeImageInfoAll() {
		makeImageInfo(Def.combo, R.drawable.combo, 0, 0, 150, 93);
	}

	public void makeImageInfo(int nTexID, int nResID, int nImgStartX,
			int nImgStartY, int nImgWidth, int nImgHeight) {
		m_imgInfo[nTexID] = new ImageInfo();

		m_imgInfo[nTexID].nResID = nResID;

		m_imgInfo[nTexID].nImgStartX = nImgStartX;
		m_imgInfo[nTexID].nImgStartY = nImgStartY;

		m_imgInfo[nTexID].nImgWidth = nImgWidth;
		m_imgInfo[nTexID].nImgHeight = nImgHeight;
	}
}
